---
description: "Reference for Nitric's v0 Python library - Receive tasks from a queue."
---

# Python - queue.receive()

Receive tasks from a queue.

```python
from nitric.resources import queue
from nitric.application import Nitric
from nitric.api import Task

batch_queue = queue('batch').allow('receiving')

tasks = await batch_queue.receive(10)

for t in tasks:
  # TODO work on the task
  # complete the task
  await t.complete()

Nitric.run()
```

## Parameters

<Properties>
  <Property name="limit" type="number">
    The maximum number of tasks to receive from the queue. Defaults to 1.
  </Property>
</Properties>

## Notes

### Completing tasks

Since the process is async, the queue doesn't know when a task has been completed. So failed services don't result in lost tasks, tasks are not removed from a queue when they're received.

Instead, tasks are hidden and receivers are granted a temporary lease for each task they receive.

When complete, the receiver must tell the queue the task was completed successfully, which will remove it from the queue and stop it being reprocessed.

<Note>
  Failing to complete a task before the lease expires will result in it being
  re-queued.
</Note>

To notify the queue that a task was completed call the `complete()` method on the task reference.

### Receive limit

When calling `receive()` a limit parameter can be provided, e.g. `receive(5)`. This will _attempt_ to receive up to 5 tasks from the queue.

However, if the queue is empty or less than 5 tasks are available on the queue, then the max available will be returned.

This means calls to receive will return between 0 and _limit_ tasks.

## Examples

### Receive tasks from a queue

```python
from nitric.resources import queue
from nitric.application import Nitric
from nitric.api import Task

batch_queue = queue('batch').allow('receiving')

tasks = await batchQueue.receive(10)

for t in tasks:
  # TODO work on the task
  # complete the task
  await t.complete()

Nitric.run()
```
